function SetOrganizationDefault(idx){
	
	var organizationId=document.getElementById("organization"+idx).value;	
	
	if(organizationId<=0)
	{
		alert('Please choose your organization!');
		return;
	}
	
	var urlLink = document.getElementById("urldefault").value + 'homepage/SetOrganizationDefault/'+organizationId;
	$.post(urlLink, {}, function(data){
		//alert('Save organization successfully.');
		setAutoHideSelectOrg('true');
		$('#closeOrgDiv').hide();
		if(idx==1){
			$("#dvhp_confirm").show();
			window.setTimeout('$("#dvhp_confirm").hide();', 1000);
		}else if(idx==0){
			$("#dvcorner_confirm").show();
			window.setTimeout('$("#dvcorner_confirm").hide();$("#popupCharity").hide();', 1000);
			 
		}
		window.setTimeout("$('#closeOrgDiv').show();", 1000);
	});	
	
	
	if(document.getElementById("charityName")!=null)
	{
		if (idx == 0) {
			document.getElementById("charityName").innerHTML = $("#organization0 option:selected").text();
			if(document.getElementById("organization1")!=null) document.getElementById("organization1").selectedIndex=document.getElementById("organization0").selectedIndex;
			if(document.getElementById("messageSelectOrg1")!=null) $("#messageSelectOrg1").html($("#messageSelectOrg0").html());
		}
		else 
		{
			document.getElementById("charityName").innerHTML = $("#organization1 option:selected").text();
			if(document.getElementById("organization0")!=null) document.getElementById("organization0").selectedIndex=document.getElementById("organization1").selectedIndex;
			if(document.getElementById("messageSelectOrg0")!=null) $("#messageSelectOrg0").html($("#messageSelectOrg1").html());
		}
	}
	if(document.getElementById("textLinkTop")!=null) document.getElementById("textLinkTop").innerHTML="Change Your Cause";
	
}

function ClosePopupCharity(){
	$("#popupCharity").hide();
	
}
function SetSelectCharity(){
	var urlLink = document.getElementById("urldefault").value + 'homepage/GetOrganizationDefault';
	$.ajax({
		  url: urlLink,
		  type: 'POST',
		  data: "",
		  success: function(x){
		  	var y = eval('(' + x + ')');
		  	if(document.getElementById("organization0")!=null) document.getElementById("organization0").value= y;
		  }
	});
}
function ShowPopupCharity(){
	$("#popupCharity").show(); 

/*
	if(document.getElementById("popupCharity").style.display=="none")
		document.getElementById("popupCharity").style.display="block";
	else
		document.getElementById("popupCharity").style.display="none" 
		*/
}

function ShowOrHideElements()
{
	if(document.getElementById("homepage").value!=1)
	{
		if(document.getElementById("greenTop")!=null) document.getElementById("greenTop").style.display="none";
		if(document.getElementById("charity_logo")!=null) document.getElementById("charity_logo").style.display="none";
		if(document.getElementById("productviewed")!=null) document.getElementById("productviewed").style.display="";
		if(document.getElementById("morebuying")!=null) document.getElementById("morebuying").style.display="";
	}
	else
	{
		if(document.getElementById("greenTop")!=null) document.getElementById("greenTop").style.display="";
		if(document.getElementById("charity_logo")!=null) document.getElementById("charity_logo").style.display="";
		if(document.getElementById("productviewed")!=null) document.getElementById("productviewed").style.display="none";
		if(document.getElementById("morebuying")!=null) document.getElementById("morebuying").style.display="none";
	}
}
function submitOrganization(){
	$("#buttonAddOrg").removeAttr('href');
	var obj = $('[name=organizationForm]').submit();
	
}
function autoHideSelectOrg(){
	var autohideselectorg = $('#autohideselectorg').val();
	if(autohideselectorg == "true"){
		$("#popupCharity").hide();	
	}
}
function setAutoHideSelectOrg(value){
	$('#autohideselectorg').val(value);
}

function showMessageSelectOrg(objOrg,objMessage){
	if($('#'+objOrg).val()=='opt1')
		$('#'+objMessage).html('');
	else if($('#'+objOrg).val()=='opt2')
		$('#'+objMessage).html('Selection of cause category will be done at checkout');
	else if($('#'+objOrg).val()=='opt3')
		$('#'+objMessage).html('Search and selection of organization will be done at checkout');
	else if($('#'+objOrg).val()=='opt4')
		$('#'+objMessage).html('A short form needs to be filled out at checkout');
	else
		$('#'+objMessage).html('');
}